package com.mrd.gtimp.business.service;

import com.mrd.base.BaseBiz;
import com.mrd.gtimp.business.entity.DictionaryGroup;
import com.mrd.spring.repository.BaseRepository;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.annotation.Resource;

/**
 * Created by dark on 17/7/12.
 */
@Service
public class DictionaryGroupBiz extends BaseBiz<DictionaryGroup> {
    @Override
    @Resource
    @Qualifier("dictionaryGroupDao")
    public void setBaseRepository(BaseRepository<DictionaryGroup, String> baseRepository) {
        this.baseRepository = baseRepository;
    }

    public DictionaryGroup findByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        String hql = "select DictionaryGroup from com.mrd.gtimp.business.entity.DictionaryGroup DictionaryGroup where DictionaryGroup.code='" + code + "'";
        List<DictionaryGroup> dictionaryGroupList = this.findEntityByHql(hql, 0, 0, null);
        if (CollectionUtils.isNotEmpty(dictionaryGroupList) && dictionaryGroupList.size() == 1) {
            return dictionaryGroupList.get(0);
        }
        return null;
    }
}
